import 'package:flutter/material.dart';
import 'package:flutterdemo01/demo56/homepage.dart';
import 'package:flutterdemo01/demo56/msgpage.dart';
import 'package:flutterdemo01/demo56/settingpage.dart';
import 'package:flutterdemo01/demo56/sportpage.dart';

class MainPage extends StatefulWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {

  int chooseIndex = 0;

  List pages = [HomePage(), MsgPage(), SportPage(), SettingPage()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('demo56'),
      ),
      body: pages[chooseIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: chooseIndex,
        unselectedItemColor: Colors.black,
        type: BottomNavigationBarType.fixed,
        unselectedLabelStyle: TextStyle(color: Colors.black),
        selectedItemColor: Colors.lightBlue,
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.message) , label: '消息'),
          BottomNavigationBarItem(icon: Icon(Icons.sports), label: '运动'),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
        ],
        onTap: (index) {
          setState(() {
            chooseIndex = index;
          });
        },
      ),
    );
  }
}
